package com.mysafe.provision.exception;

public class ValidationError {
	
	public static final Integer REQUIRED = 1;
	public static final Integer INVALID = 2;
	public static final Integer INTEGRITY = 3;
	
	private Integer type;
	private String field;
	private String message;
	
	public ValidationError() {
	}
	
	public ValidationError(Integer type) {
		this.type = type;
		setDefaultMessage(type);
	}

	public ValidationError(Integer type, String message) {
		this.type = type;
		this.message = message;
	}

	public ValidationError(Integer type, String field, String message) {
		this.type = type;
		this.field = field;
		this.message = message;
	}

	private void setDefaultMessage(Integer type) {
		if (type != null) {
			if (type.equals(INVALID)) {
				message = "An error occurred.";
			} else if (type.equals(INTEGRITY)) {
				message = "Integrity error.";
			} else if (type.equals(REQUIRED)) {
				message = "Missing required information.";
			}
		}
	}

	@Override
	public String toString() {
		return message;
	}
	
	/**
	 * @return the type
	 */
	public Integer getType() {
		return type;
	}

	/**
	 * @param type the type to set
	 */
	public void setType(Integer type) {
		this.type = type;
	}

	/**
	 * @return the field
	 */
	public String getField() {
		return field;
	}

	/**
	 * @param field the field to set
	 */
	public void setField(String field) {
		this.field = field;
	}

	/**
	 * @return the message
	 */
	public String getMessage() {
		return message;
	}

	/**
	 * @param message the message to set
	 */
	public void setMessage(String message) {
		this.message = message;
	}
	
	

}
